<?php 
	include_once 'dataservice.php';
	include_once 'thuvienham.php';

	class phonghoc_db 
	{
		public function Them($MaPhong, $TenPhong, $SoLuongMay, $SoMayHoatDong, $MaTrangThai, $PIN)
		{
			$sql = "INSERT INTO `tbl_phonghoc`(`MaPhong`, `TenPhong`, `SoLuongMay`, `SoMayHoatDong`, `MaTrangThai`, `PIN`)
					VALUES ('$MaPhong', '$TenPhong', '$SoLuongMay', '$SoMayHoatDong', '$MaTrangThai', '$PIN')";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function Xoa($MaPhong)
		{
			$sql = "DELETE FROM `tbl_phonghoc` WHERE `MaPhong` = '$MaPhong'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function CapNhat($MaPhong, $TenPhong, $SoLuongMay, $SoMayHoatDong, $MaTrangThai, $PIN)
		{
			$sql = "UPDATE `tbl_phonghoc`
					SET `TenPhong` = '$TenPhong', `SoLuongMay` = '$SoLuongMay', `SoMayHoatDong` = '$SoMayHoatDong', `MaTrangThai` = '$MaTrangThai', `PIN` = '$PIN'
					WHERE `MaPhong` = '$MaPhong'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function LayDanhSach($MaPhong, $TenPhong, $SoLuongMay, $SoMayHoatDong, $MaTrangThai, $PIN)
		{
			$sql = "SELECT * FROM `tbl_phonghoc` WHERE 1  ";
			if($MaPhong != "")
				$sql .= " AND `MaPhong` = '$MaPhong' ";

			if($TenPhong != "")
				$sql .= " AND `TenPhong` = '$TenPhong' ";

			if($SoLuongMay != -1)
				$sql .= " AND `SoLuongMay` = '$SoLuongMay' ";

			if($SoMayHoatDong != -1)
				$sql .= " AND `SoMayHoatDong` = '$SoMayHoatDong' ";

			if($MaTrangThai != -1)
				$sql .= " AND `MaTrangThai` = '$MaTrangThai' ";

			if($PIN != "")
				$sql .= " AND `PIN` = '$PIN' ";

			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}

	}

